package com.amkai.mobile.client.appointmentdetails;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.amkai.mobile.bean.pmcase.MobileCase;
import com.amkai.mobile.bean.scheduler.appointment.MobileAppointmentDetails;
import com.amkai.mobile.client.R;
import com.amkai.mobile.client.common.AEMobileConstants;
import com.amkai.mobile.common.job.scheduler.MobileSchedulerJob;
import com.amkai.mobile.common.job.scheduler.MobileSchedulerJobResult;
import com.amkai.mobile.utils.manager.job.MobileServiceManager;

/**
 * 
 * @author lkovari
 *
 */
public class CaseTab extends Activity {
	private TextView casenameTextView = null;
	private TextView statusTextView = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.pmcasetab);

        // capture ids
        Bundle bundle = getIntent().getExtras();
        Long beId = bundle.getLong(AEMobileConstants.BUNDLE_CONTENT_TAG_DEPARTMENTID);
        Long passId = bundle.getLong(AEMobileConstants.BUNDLE_CONTENT_TAG_PASSPORTID);
        Long apptId = bundle.getLong(AEMobileConstants.BUNDLE_CONTENT_TAG_APPOINTMENTID);
        
        // download appointmentTetails
		try {
//			MobileSchedulerJobResult schedulerResult = MobileServiceManager.processMobileJob(CaseTab.this, MobileSchedulerJob.appointmentDetailsById(apptId));
			MobileSchedulerJobResult schedulerResult = MobileServiceManager.processMobileJob(CaseTab.this, MobileSchedulerJob.caseDetailsById(apptId));			
			if (schedulerResult.getException() == null) {
//				MobileAppointmentDetails mobileAppointmentDetails = schedulerResult.getMobileAppointmentDetails();
//				showCaseDetails(mobileAppointmentDetails.mobileCase);
				MobileCase mobileCase = schedulerResult.getMobileCase();
				showCaseDetails(mobileCase);
			}
			else {
				Toast msg = Toast.makeText(CaseTab.this, "Download case data failed!", Toast.LENGTH_SHORT);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void showCaseDetails(MobileCase mobileCase) {
		casenameTextView = (TextView) findViewById(R.id.casenameLabelValueTextField);
		casenameTextView.setText(mobileCase.name); 
        statusTextView = (TextView) findViewById(R.id.casestatusLabelValueTextField);
        statusTextView.setText(mobileCase.status);
	}
}
